# -*- coding: utf-8 -*-
#高级特性----filter()也接收一个函数和一个序列。和map()不同的是，
# filter()把传入的函数依次作用于每个元素，然后根据返回值是True还是False决定保留还是丢弃该元素。

import io
import sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf-8')

def is_odd(n):
	return n % 2 == 1
print(list(filter(is_odd,[1,2,3,4,5,6,7,8,9,10])))

def not_empty(s):
	return s and s.strip()
print(list(filter(not_empty,['a','','b',None])))

def is_palindrome(s):
	return str(s) == str(s)[::-1]

output = filter(is_palindrome, range(1, 1000))
print('1~1000:', list(output))
if list(filter(is_palindrome, range(1, 200))) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121, 131, 141, 151, 161, 171, 181, 191]:
    print('测试成功!')
else:
    print('测试失败!')